package com.zf.zfed.audit.base

import androidx.fragment.app.Fragment
import com.blankj.utilcode.util.FragmentUtils
import com.blankj.utilcode.util.LogUtils
import com.zf.zfed.audit.R
import com.zf.zfed.audit.action.HandlerAction
import com.zf.zfed.audit.ui.ZFHomeActivity

enum class TabContainer(val containerId: Int) {
    SYSTEM_SET(R.id.set_frame_layout)
}

open class BaseFragment : Fragment(), HandlerAction {

    fun pushFragment(fragment: Fragment, from: TabContainer) {
        FragmentUtils.add(
            parentFragmentManager,
            fragment,
            from.containerId,
            fragment.toString(),
            false,
            true
        )

        // 隐藏Tab
//        val activity = requireActivity()
//        if (activity is ZFHomeActivity) {
//            activity.hideBottomTabBar()
//        }
    }

    fun popFragment() {
        try {
            if (FragmentUtils.getAllFragmentsInStack(parentFragmentManager).count() == 1) {
//                val activity = requireActivity()
//                if (activity is ZFHomeActivity) {
//                    activity.showBottomTabBar()
//                }
            }
            FragmentUtils.pop(parentFragmentManager, true)
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    override fun onDestroy() {
        LogUtils.d("BaseFragment: Releasing resources for ${this.javaClass.simpleName}")
        super.onDestroy()
    }
}